package aliyunCli

import (
	"fmt"
	"tushare/conf"

	ecs "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
)

type AttachKeyPair struct {
}

func (akp AttachKeyPair) AttachKeyPair(instanceId, keyPairName string) {
	client, err := ecs.NewClientWithAccessKey("cn-hangzhou", conf.AccessKeyID, conf.AccessKeySecret)

	request := ecs.CreateAttachKeyPairRequest()
	request.Scheme = "https"

	//hadoop
	request.KeyPairName = keyPairName
	request.InstanceIds = fmt.Sprintf("['%s']", instanceId)

	_, err = client.AttachKeyPair(request)
	if err != nil {
		fmt.Print(err.Error())
	}
}
